package com.cloud.admin.controller.ajax;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cloud.admin.controller.BaseController;
import com.cloud.admin.model.entity.MLanguage;
import com.cloud.common.util.AjaxResultUtils;
import com.cloud.common.util.HttpReturnRnums;
import com.cloud.admin.service.MLanguageService;
import com.cloud.admin.common.core.domain.AjaxResult;
import com.cloud.admin.common.core.page.TableDataInfo;
import lombok.AllArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.stream.Collectors;

/**
 * 语言
 *
 * @author douhaichao code generator
 * @date 2022-10-04 09:20:55
 */
@RestController
@RequestMapping("ajax/mlanguage")
@AllArgsConstructor
public class Ajax_MLanguageController extends BaseController {

    private final MLanguageService mLanguageService;

    @RequiresPermissions("admin:mlanguage:list")
    @PostMapping(value = "listdo")
    public TableDataInfo listdo(Page page, MLanguage req) {
        IPage<MLanguage> pageInfo = mLanguageService.selectPageByLike(page, req);
        return getDataTable(pageInfo);
    }

    @RequiresPermissions("admin:mlanguage:remove")
    @PostMapping("remove")
    public AjaxResult remove(String ids)
    {
        try
        {
            return toAjax(mLanguageService.removeByIds(Arrays.stream(ids.split(",")).collect(Collectors.toList())));
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
    }

    @RequiresPermissions("admin:mlanguage:add")
    @PostMapping("add")
    public AjaxResult addSave(@Validated MLanguage req)
    {
        return toAjax(mLanguageService.save(req));
    }

    @RequiresPermissions("admin:mlanguage:edit")
    @PostMapping("edit")
    public AjaxResult editSave(@Validated MLanguage req)
    {
        return toAjax(mLanguageService.updateById(req));
    }
}
